<?php

namespace App\Models\ChatGroup;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

class ChatGroupDataStatisticsModel extends BaseModel
{
    use KfUid;

    protected $table = 'chat_group_data_statistics';

    protected $fillable = [
        'id',
        'groupId',
        'shopId',
        'sessionId',
        'statisticData',
        'type',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
    ];

    const TYPE_CALL                   = 1;
    const TYPE_CALL_TIME              = 2;
    const TYPE_CALL_CUSTOMER          = 3;
    const TYPE_FAQ_ANSWER_USE_FULL    = 4;
    const TYPE_FAQ_ANSWER_USE_LESS    = 5;
    const TYPE_FAQ_ANSWER_USE_FULL_AI = 6;
    const TYPE_FAQ_ANSWER_USE_LESS_AI = 7;

    const TYPE_TEXT_MAPPING = [
        self::TYPE_CALL                   => '发起呼叫',
        self::TYPE_CALL_TIME              => '响应时长',// 单位s
        self::TYPE_CALL_CUSTOMER          => '人工客服介入',
        self::TYPE_FAQ_ANSWER_USE_FULL    => '问题答案有用',
        self::TYPE_FAQ_ANSWER_USE_LESS    => '问题答案无用',
        self::TYPE_FAQ_ANSWER_USE_FULL_AI => '问题答案卡AI有用',
        self::TYPE_FAQ_ANSWER_USE_LESS_AI => '问题答案卡AI无用',
    ];


    /**
     * @param int $shopId
     * @param int $groupId
     * @param int $sessionId
     * @param int $statisticData
     * @param int $type
     * @return Builder|Model
     */
    public function recordDataStatistics(int $shopId, int $groupId, int $sessionId, int $statisticData, int $type)
    {
        return self::query()->create([
            'shopId'        => $shopId,
            'groupId'       => $groupId,
            'sessionId'     => $sessionId,
            'statisticData' => $statisticData,
            'type'          => $type,
        ]);
    }
}
